home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / editAttrLimits.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  3.9 KB  |  117 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. // Copyright (C) 1997-2000 Alias|Wavefront,
  18. // a division of Silicon Graphics Limited.
  19. //
  20. // The information in this file is provided for the exclusive use of the
  21. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  22. // and incorporate this code into other products for purposes authorized
  23. // by the Alias|Wavefront license agreement, without fee.
  24. //
  25. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  26. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  27. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  28. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  29. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  30. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  31. // PERFORMANCE OF THIS SOFTWARE.
  32. //
  33. //<doc>
  34. //<name editAttrLimits>
  35. //<owner "Alias|WaveFront Unsupported">
  36. //<synopsis>
  37. //     void editAttrLimits(string $attr, float $min, float $max)
  38. //<keywords>
  39. //        edit attribute limits min max
  40. //<related addAttr>
  41. //
  42. //<description>
  43. //      Edit the attribute min and max of dynamic attributes.
  44. //
  45. //<flags>
  46. //        string    $attr    Attribute to be altered
  47. //        float    $min    New attribute minimum
  48. //        float    $max    New attribute maximum
  49. //
  50. //<examples>
  51. //      createNode -n sinNode transform;
  52. //        addAttr -at double -min 0.0 -max 2.0 -ln sinValue;
  53. //        attributeQuery -r -n sinNode sinValue;
  54. //        // Result: 0 2 //
  55. //        editAttrLimits( "sinNode.sinValue", -1.0, 1.0 );
  56. //        attributeQuery -r -n sinNode sinValue;
  57. //        // Result: -1 1 //
  58. //
  59. //<notes>
  60. //      This command only works on numeric type attributes that can have
  61. //      limits defined.  No checking is performed to verify the attribute
  62. //        type so check types before calling it.
  63. //
  64. //</doc>
  65. //
  66. global proc editAttrLimits (string $objectAttr, float $min, float $max)
  67. {
  68.     // this script will allow the user to edit the min and max value of an
  69.     // attribute
  70.  
  71.     // first find out what connections are going into and out of the object
  72.     $input = `listConnections -source true -d false -p true $objectAttr`;
  73.     $output = `listConnections -source false -d true -p true $objectAttr`;
  74.  
  75.     // get the current value of the attr
  76.     $val = `getAttr $objectAttr`;
  77.  
  78.     // break the connections if they exist
  79.     string $dest;
  80.     if (size($input) > 0)
  81.     {
  82.         disconnectAttr $input[0] $objectAttr;
  83.     }
  84.     for( $dest in $output )
  85.     {
  86.         disconnectAttr $objectAttr $dest;
  87.     }
  88.  
  89.     // now tokenize $objectAttr in order to get it's individual parts
  90.     string $parts[2];
  91.     tokenize ($objectAttr, ".", $parts);
  92.     $object = $parts[0];
  93.     $attr = $parts[1];
  94.  
  95.     // get the type of attribute this is
  96.     $type = `getAttr -type $objectAttr`;
  97.  
  98.     // delete the attribute
  99.     deleteAttr -at $attr $object;
  100.  
  101.     // re-create the attribute with the new min/max
  102.     addAttr -at $type -ln $attr -min $min -max $max $object;
  103.  
  104.     // set the value to be what it used to be
  105.     setAttr $objectAttr $val;
  106.  
  107.     // remake the connections
  108.     if (size($input) > 0)
  109.     {
  110.         connectAttr $input[0] $objectAttr;
  111.     }
  112.     for( $dest in $output )
  113.     {
  114.         connectAttr $objectAttr $output;
  115.     }
  116. }
  117.